/*
 *  This file is part of Bracket Properties
 *  Copyright 2011-2013 David R. Smith
 *  All Rights Reserved
 *
 */
package asia.redact.bracket.properties.serializer;

import java.util.ArrayList;
import java.util.List;

import asia.redact.bracket.properties.Properties;

/**
 * Wrapper implements (almost) the Decorator pattern - it allows multiple Renderers 
 * to operate on the single pass through the graph. 
 * 
 * @author Dave
 *
 */
public class Wrapper implements Renderer {

	List<Renderer> list;

	public Wrapper() {
		list = new ArrayList<Renderer>();
	}

	public void addRenderer(Renderer r) {
		list.add(r);
	}
	
	public Properties getProperties() {
		for (Renderer r : list) {
			if(r instanceof PropertiesRenderer){
				return ((PropertiesRenderer)r).getProps();
			}
		}
		return null;
	}

	@Override
	public void renderImmediateMapValue(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderImmediateMapValue(parent, child, ct);
		}
	}

	@Override
	public void renderIndirectMapValue(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderIndirectMapValue(parent, child, ct);
		}

	}

	@Override
	public void renderImmediate(Token parent, Token child) {
		for (Renderer r : list) {
			r.renderImmediate(parent, child);
		}

	}

	@Override
	public void renderIndirect(Token parent, Token child) {
		for (Renderer r : list) {
			r.renderIndirect(parent, child);
		}

	}

	@Override
	public void renderImmediateMapKey(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderImmediateMapKey(parent, child, ct);
		}

	}

	@Override
	public void renderIndirectMapKey(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderIndirectMapKey(parent, child, ct);
		}

	}

	@Override
	public void renderParentClass(Token parent) {
		for (Renderer r : list) {
			r.renderParentClass(parent);
		}

	}

	@Override
	public void renderValue(Token parent) {
		for (Renderer r : list) {
			r.renderValue(parent);
		}

	}

	@Override
	public void renderImmediateListItem(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderImmediateListItem(parent, child, ct);
		}

	}

	@Override
	public void renderIndirectListItem(Token parent, Token child, int ct) {
		for (Renderer r : list) {
			r.renderIndirectListItem(parent, child, ct);
		}

	}

	@Override
	public void renderCharArray(Token token) {
		for (Renderer r : list) {
			r.renderCharArray(token);
		}
	}

	@Override
	public void renderByteArray(Token token) {
		for (Renderer r : list) {
			r.renderByteArray(token);
		}

	}

	@Override
	public void renderIntArray(Token token) {
		for (Renderer r : list) {
			r.renderIntArray(token);
		}

	}

	@Override
	public void renderLongArray(Token token) {
		for (Renderer r : list) {
			r.renderLongArray(token);
		}

	}

	@Override
	public void renderInitialKeyId(Token root) {
		for (Renderer r : list) {
			r.renderInitialKeyId(root);
		}
	}

	@Override
	public void renderLastKeyId(long last) {
		for (Renderer r : list) {
			r.renderLastKeyId(last);
		}
		
	}

	@Override
	public void renderDoubleArray(Token token) {
		for (Renderer r : list) {
			r.renderDoubleArray(token);
		}
		
	}

	@Override
	public void renderBooleanArray(Token token) {
		for (Renderer r : list) {
			r.renderBooleanArray(token);
		}
	}

	@Override
	public void renderFloatArray(Token token) {
		for (Renderer r : list) {
			r.renderFloatArray(token);
		}
		
	}

	@Override
	public void renderShortArray(Token token) {
		for (Renderer r : list) {
			r.renderShortArray(token);
		}
		
	}

	@Override
	public void renderLoadable(Token token) {
		for (Renderer r : list) {
			r.renderLoadable(token);
		}
	}

	@Override
	public void renderClassMap() {
		for (Renderer r : list) {
			r.renderClassMap();
		}
		
	}

}
